package com.ztools.pc.controller.store;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.common.model.pc.store.StoreStock;
import com.ztools.common.util.common.PageUtil;
import com.ztools.common.util.common.Result;
import com.ztools.pc.service.store.StoreStockService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author seeTools
 * @since 2023-05-28
 */
@RestController
@RequestMapping("/store/stock")
public class StoreStockController {

    @Resource
    private StoreStockService storeStockService;

    @PostMapping("/list")
    public Result findList(@RequestBody PageUtil<StoreStock> pageUtil) {
        Page<StoreStock> list = storeStockService.findList(pageUtil);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/findByObject")
    public Result findByObject(@RequestBody StoreStock storeStock) {
        List<StoreStock> list = storeStockService.findByObject(storeStock);
        return list != null ? Result.success("查询成功").data(list) : Result.error();
    }

    @RequestMapping("/update")
    public Result update(@RequestBody StoreStock storeStock) {
        boolean b = storeStockService.update(storeStock);
        return b ? Result.success("修改成功") : Result.error();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestBody StoreStock storeStock) {
        boolean b = storeStockService.delete(storeStock);
        return b ? Result.success("删除成功") : Result.error();
    }

    @RequestMapping("/add")
    public Result add(@RequestBody StoreStock storeStock) {
        boolean b = storeStockService.save(storeStock);
        return b ? Result.success("添加成功") : Result.error();
    }

    @RequestMapping("/updateSalePrice")
    public Result updateSalePrice(@RequestBody StoreStock storeStock) {
        boolean b = storeStockService.updateSalePrice(storeStock);
        return b ? Result.success("修改成功") : Result.error();
    }
}
